import { onMounted, ref } from "vue";
import { useRoute } from "vue-router";
import {onBeforeRouteUpdate} from 'vue-router'
import { getCategoryAPI } from "@/apis/category";
export function useCategory(){
  let categoryData=ref({})
  const route=useRoute();
  async function getCategory(id){
    let res=await getCategoryAPI(id);
    categoryData.value=res.result;
  }
  getCategory(route.params.id);
  onBeforeRouteUpdate((to)=>{
    getCategory(to.params.id);
  })
  return{
    categoryData,
  }
}
